package org.ttitfly.ttcore.web.menu;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.ttitfly.ttcore.entity.menu.SystemMenu;
import org.ttitfly.ttcore.service.menu.SystemMenuManager;
import org.ttitfly.ttcore.util.tree.TreeNode;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GetMenuTreeChildrenAction extends ActionSupport{
	String key;
	List<TreeNode> children = new ArrayList<TreeNode>();
	@Autowired
	private SystemMenuManager systemMenuManager;
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public List<TreeNode> getChildren() {
		return children;
	}
	public void setChildren(List<TreeNode> children) {
		this.children = children;
	}
	
	
	
	public String execute(){
//		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//		children = privilegeMgmtService.getOPPrivilegeChildTreeNodeList(key, domainId);
		List<SystemMenu> list = systemMenuManager.findBy("parentId", Long.parseLong(key),"id",true);
		for(SystemMenu menu : list){
			boolean leaf = false;
			if(menu.getLeaf()==1){
				leaf = true;
			}
			TreeNode node = new TreeNode(""+menu.getId(),menu.getTitle(),leaf);
			children.add(node);
		}
		return SUCCESS;
	}
	public SystemMenuManager getSystemMenuManager() {
		return systemMenuManager;
	}
	public void setSystemMenuManager(SystemMenuManager systemMenuManager) {
		this.systemMenuManager = systemMenuManager;
	}
	
	
}

